package com.sinothk.fc.bo.supply.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sinothk.fc.bo.supply.entity.BoSupplyEntity;
import com.sinothk.fc.bo.supply.entity.BoSupplyOrderVO;
import com.sinothk.fc.bo.supply.entity.BoSupplyVO;
import com.sinothk.fc.bo.supply.entity.SupplySearchReq;
import com.sinothk.fc.bo.supply.mapper.BoSupplyMapper;
import com.sinothk.fc.bo.supply.service.IBoSupplyService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description: 商机供应
 * @Author: Liangyt
 * @Date:   2022-10-23
 * @Version: V1.0
 */
@Service
public class BoSupplyServiceImpl extends ServiceImpl<BoSupplyMapper, BoSupplyEntity> implements IBoSupplyService {

    @Resource
    private BoSupplyMapper supplyMapper;

    @Override
    public IPage<BoSupplyVO> demandSupplyGoodsForDemandIdPage(Page<BoSupplyEntity> page, String demandId) throws Exception {
        if (StringUtils.isBlank(demandId)) throw new Exception("需求ID不能为空");
        return supplyMapper.demandSupplyGoodsForDemandIdPage(page, demandId);
    }

    @Override
    public IPage<BoSupplyOrderVO> supplyGoodsOrderPage(Page<BoSupplyEntity> page) throws Exception {

        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (loginUser == null) throw new Exception("当前用户信息有误");
        if (StringUtils.isBlank(loginUser.getStoreId())) throw new Exception("当前用户没有门店id");

        SupplySearchReq searchReq = new SupplySearchReq();
        searchReq.setStoreId(loginUser.getStoreId());
        return supplyMapper.supplyGoodsOrderPage(page, searchReq);
    }
}
